import { Pipe, PipeTransform, Injectable } from '@angular/core'
import { TranslateService } from '@ngx-translate/core'

// i18n materials of payment brand is prefix with PAYMENT_BRAND.
@Pipe({ name: 'i18nPrefixWith' })
@Injectable({
  providedIn: 'root',
})
export class I18NPrefixWithPipe implements PipeTransform {
  constructor(private translate: TranslateService) {}

  transform(value: string, prefix?: string): string {
    if (value === undefined) {
      return this.translate.instant('GENERAL.INFO.NONE')
    }
    if (prefix === undefined) {
      prefix = ''
    }
    const result = this.translate.instant(`${prefix}${value}`)
    return result
  }
}
